# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/15'
__author__ = 'Just'
__filename__ = 'comic'
"""
from app.model.comic_image import ComicImage


class ComicService:
    cid = None           # 漫画id
    sid = None           # 章节id
    pid = 1              # 内容阅读进度id
    images = []  # 当前章节的所有图片
    total = 0            # 图片数量

    def __init__(self, cid, sid):
        self.cid = cid
        self.sid = sid

    def get_content(self):
        """获取某章的所有图片"""
        _images = ComicImage.query.order_by(ComicImage.pid).filter(
                    ComicImage.cid == self.cid, ComicImage.sid == self.sid, ComicImage.status == 1).all()
        self.images = [item.hide('cid', 'sid') for item in _images]
        self.total = len(_images)

    def save_pid(self, index):
        self.pid = index
